home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / GMS / Source / Asm / System / StartGMS.s < prev   
Encoding:
Text File  |  1997-04-25  |  6.5 KB  |  231 lines

  1. ;START GMS
  2. ;---------
  3. ;Usage:   StartGMS <TaskFile>
  4. ;Author:  Paul Manias
  5. ;Version: V0.1B
  6. ;Date:    25/4/97
  7. ;Docs:    This program is intended to allow multi-platform capabilities by
  8. ;      doing things like opening GMS for the task.  For example the
  9. ;      following code would not work on a Mac even if it is 68000 code:
  10. ;
  11. ;      move.l $4.w,a6
  12. ;      ...
  13. ;      CALL   OpenLibrary
  14. ;
  15. ;      To fix this problem we put this machine-specific code in a task
  16. ;      launcher (StartGMS) and pass the GMSBase onto the task.  Alakazam,
  17. ;      multiple platform capabilities!
  18. ;
  19. ;PROBLEMS: Programs written in E cannot cope with this as far as I know :-(.
  20.  
  21.     INCDIR    "INCLUDES:"
  22.     INCLUDE    "exec/exec_lib.i"
  23.     INCLUDE    "dos/dos_lib.i"
  24.     INCLUDE    "exec/libraries.i"
  25.  
  26. CALL    MACRO
  27.     jsr    _LVO\1(a6)
  28.     ENDM
  29.  
  30.     SECTION    "StartGMS",CODE
  31.  
  32. ;===================================================================================;
  33. ;                                INITIALISE PROGRAM
  34. ;===================================================================================;
  35. ;Requires: a0 = Pointer to file to load???
  36.  
  37. Start:    MOVEM.L    A0-A6/D0-D7,-(SP)
  38.     move.l    a0,CommandLine
  39.     move.l    d0,AmtCommands
  40.  
  41.     move.l    ($4).w,a6
  42.     lea    DOSName(pc),a1
  43.     moveq    #$00,d0
  44.     CALL    OpenLibrary
  45.     move.l    d0,DOSBase
  46.     beq.s    .Error_DOS
  47.  
  48.     lea    GMSName(pc),a1
  49.     moveq    #$00,d0
  50.     CALL    OpenLibrary
  51.     move.l    d0,GMSBase
  52.     beq.s    .Error_GMS
  53.  
  54.     cmp.l    #1,AmtCommands
  55.     ble.s    .ReturnToDOS
  56.     move.l    CommandLine(pc),a0
  57.     cmp.b    #"?",(a0)
  58.     bne.s    .go
  59.     bsr.s    Usage
  60.     bra.s    .ReturnToDOS
  61.  
  62. .go    bsr.s    ParseArguments
  63.     tst.l    d0
  64.     bne.s    .ReturnToDOS
  65.     bsr    Launch
  66.     bsr    FreeArguments
  67.  
  68. .ReturnToDOS:
  69.     move.l    ($4).w,a6
  70.     move.l    DOSBase(pc),a1
  71.     CALL    CloseLibrary
  72. .Error_GMS
  73. .Error_DOS
  74.     MOVEM.L    (SP)+,A0-A6/D0-D7
  75.     moveq    #$00,d0
  76.     rts
  77.  
  78. ;===================================================================================;
  79. ;                             PRINT USAGE INFORMATION
  80. ;===================================================================================;
  81.  
  82. Usage:    move.l    DOSBase(pc),a6
  83.     CALL    Output
  84.     move.l    d0,d1    ;d1 = File handle to write out to.
  85.     move.l    #TXT_Usage,d2    ;d2 = Pointer to buffered text.
  86.     move.l    #TXT_UsageSize,d3    ;d3 = Size of text.
  87.     CALL    Write
  88.     rts
  89.  
  90. ;===================================================================================;
  91. ;                                 PARSE ARGUMENTS
  92. ;===================================================================================;
  93. ;Template is: StartGMS <TaskFile> [PREFS <Name>] <Arg1> <Arg2> ...
  94.  
  95. ParseArguments:
  96.     move.l    CommandLine(pc),a0    ;a0 = Pointer to first char of <TaskFile>.
  97.     moveq    #$00,d0    ;d0 = Byte count of file name.
  98. .loop    cmp.b    #10,(a0)    ;a0 = Check for return key.
  99.     beq.s    .key_return    ;>> = Return key found.
  100.     cmp.b    #' ',(a0)    ;a0 = Check for space key.
  101.     beq.s    .key_space    ;>> = Return key found.
  102.     addq.l    #1,d0    ;d0 = ++1
  103.     addq.w    #1,a0    ;a0 = ++1
  104.     bra.s    .loop    ;>> = Keep looping till we find the end.
  105.  
  106. .key_return
  107.     move.b    #' ',(a0)    ;a0 = Replace return key with a space.
  108. .key_space
  109.     addq.l    #1,a0    ;a0 = ++1
  110.     move.l    a0,TaskArgs    ;MA = Save pointer to GMS task args.
  111.     move.l    ($4).w,a6    ;a6 = ExecBase
  112.     addq.l    #1,d0    ;d0 = (MemSize)+1 [For null termination]
  113.     move.l    d0,sizeTaskFile    ;MA = Make a note of the size allocated.
  114.     moveq    #$0,d1    ;d1 = MemType
  115.     CALL    AllocMem    ;>> = AllocMem(Size:d0,Type:d1)
  116.     move.l    d0,TaskFile    ;MA = Pointer to file memory.
  117.     beq.s    .Error_Memory    ;>> = Memory error.
  118.  
  119.     move.l    CommandLine(pc),a0    ;a0 = Command Line source.
  120.     move.l    TaskFile(pc),a1    ;a1 = FileName destination.
  121. .cloop    cmp.b    #" ",(a0)    ;a0 = Check for space.
  122.     beq.s    .done    ;>> = Got it.
  123.     move.b    (a0)+,(a1)+    ;a1 = Copy Character++
  124.     bra.s    .cloop    ;>> = Keep looping.
  125.  
  126. .done    clr.b    (a1)+
  127.     moveq    #$00,d0    ;d0 = No errors.
  128.     rts
  129.  
  130. .Error_Memory
  131.     moveq    #$01,d0    ;d0 = Memory error.
  132.     rts
  133.  
  134. FreeArguments:
  135.     move.l    ($4).w,a6    ;a6 = ExecBase.
  136.     move.l    TaskFile(pc),a1    ;a1 = Pointer to allocated block.
  137.     move.l    sizeTaskFile(pc),d0    ;d0 = Size of allocated block.
  138.     CALL    FreeMem    ;>> = Free it.
  139.     rts
  140.  
  141. ;===================================================================================;
  142. ;                                LAUNCH GMS PROGRAM
  143. ;===================================================================================;
  144. ;Load the program in with LoadSeg() and then run it (remembering to pass the
  145. ;necessary variables).  On other machines this part will have to be modified to
  146. ;recognise and load in Amiga formatted file hunks.
  147. ;
  148. ;Sends: a0 = Command Line Parameters
  149. ;    a1 = GMSBase
  150. ;    a2 = Pointer to address of program.
  151. ;    d0 = "GMSP" Identification.
  152. ;    d1 = Amount of commands on line.
  153. ;    d2 = (Version<<16)|(Revision)
  154.  
  155. Launch:    move.l    DOSBase(pc),a6    ;a6 = DOS Base.
  156.     move.l    TaskFile(pc),d1    ;d1 = Pointer to file name.
  157.     CALL    LoadSeg    ;>> = Go and load the executable.
  158.     move.l    d0,Segment    ;MA = Store pointer to segment.
  159.     beq.s    .Error_Segment    ;>> = Error loading file :-(
  160.  
  161.     ;Setup parameters here.
  162.  
  163.     move.l    Segment(pc),d0    ;d0 = BCPL pointer to segment.
  164.     add.l    d0,d0    ;d0 = *2
  165.     add.l    d0,d0    ;d0 = *4
  166.     move.l    d0,a2    ;a2 = Pointer to start of seglist.
  167.     move.l    GMSBase(pc),a1    ;a1 = Pointer to GMSBase.
  168.     move.l    #"GMSP",d0    ;d0 = "GMSP"
  169.  
  170.     move.w    LIB_VERSION(a1),d2    ;d2 = Version
  171.     swap    d2    ;d2 = (Version)<<16
  172.     move.w    LIB_REVISION(a1),d2    ;d2 = (Version<<16)|(Revision)
  173.  
  174.     sub.l    a3,a3    ;Clear all other registers before
  175.     sub.l    a4,a4    ;launching the task.
  176.     sub.l    a5,a5
  177.     sub.l    a6,a6
  178.     moveq    #$00,d2
  179.     moveq    #$00,d3
  180.     moveq    #$00,d4
  181.     moveq    #$00,d5
  182.     moveq    #$00,d6
  183.     moveq    #$00,d7
  184.     jsr    4(a2)    ;>> = Start the GMS program.
  185.  
  186.     move.l    DOSBase(pc),a6    ;a6 = DOS Base.
  187.     move.l    Segment(pc),d1    ;d1 = BCPL segment pointer.
  188.     CALL    UnLoadSeg    ;>> = Unload the program.
  189. .Error_Segment
  190.     rts
  191.  
  192. ;===================================================================================;
  193. ;                                       DATA
  194. ;===================================================================================;
  195.  
  196. GMSName: dc.b    "GMS:GPI/Master.GPI",0
  197.      even
  198. DOSName: dc.b    "dos.library",0
  199.      even
  200.  
  201. GMSBase:  dc.l    0    ;Pointer to GMSBase.
  202. DOSBase:  dc.l    0
  203.  
  204. TaskFile:    dc.l  0    ;Name of file to load.
  205. sizeTaskFile dc.l  0    ;Size of allocated memory block.
  206. Segment:     dc.l  0    ;Pointer to segment of loaded file.
  207. CommandLine  dc.l  0    ;Pointer to first command line argument.
  208. AmtCommands: dc.l  0    ;Amount of arguments on command line.
  209. TaskArgs:    dc.l  0    ;Arguments for the GMS Task.
  210.  
  211. TXT_Usage:
  212.  dc.b    10
  213.  dc.b    "STARTGMS",10
  214.  dc.b    "--------",10
  215.  dc.b    "This program will launch GMS tasks for you, and in future will",10
  216.  dc.b    "be required for setting up GMS games that have been compiled on other",10
  217.  dc.b    "platforms.",10
  218.  dc.b    10
  219.  dc.b    "To use it, just type:",10
  220.  dc.b    10
  221.  dc.b    "  1> StartGMS <FileName> <Arg1> <Arg2> <Arg3> ...",10
  222.  dc.b    10
  223.  dc.b    "Example:",10
  224.  dc.b    10
  225.  dc.b    "  1> StartGMS GMS:demos/Redimension",10
  226.  dc.b    10
  227.  dc.b    0
  228.  
  229. TXT_UsageSize = *-TXT_Usage
  230.  
  231.